<?php
namespace app\store\controller\wxapp;
use app\store\controller\Controller;
use app\store\model\WxappReg as WxappRegModel;
use app\store\model\WebSet as WebSetModel;
use app\store\model\StoreUser as StoreUserModel;
/**
 * 快速注册小程序
 */
class Register extends Controller
{
    /**
     * 快速注册小程序
     */
    public function index()
    {
		$values = WebSetModel::getItem('pay');
		if($values['examine']>0){
			$store = StoreUserModel::detail($this->store['user']['store_user_id']);
			if($store['wallet'] < $values['examine']){
				$this->error('您账户余额不足？需缴纳￥'. $values['examine'] .'注册费用！','/index.php?s=/index/user/wallet');
				return false;
			}
		}
		$model = WxappRegModel::detail();
		if(!$this->request->isAjax()) {
            return $this->fetch('index', compact('model'));
        }
		//提交动作
		$data = $this->postData('register');
		//新增
		if($data['status']==0){
			$model = new WxappRegModel;
			if ($model->add($data,$values['examine'],$this->store['user']['store_user_id'])) {
				sand_examine_msg($model->wxapp_reg_id,'注册小程序 - 新增资料','待处理');
				return $this->renderSuccess('操作成功，等待审核', url('wxapp.register/index'));
			}
			$error = $model->getError() ?: '操作失败';
			return $this->renderError($error);
		}
		//修改
        if ($model->edit($data)) {
			sand_examine_msg($model->wxapp_reg_id,'注册小程序 - 修改资料','待处理');
			return $this->renderSuccess('操作成功，等待审核', url('wxapp.register/index'));
        }
        $error = $model->getError() ?: '操作失败';
        return $this->renderError($error);        
    }

}
